package com.kupurui.asteacher.ui.index;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.adapter.BindingAuditAdapter;
import com.kupurui.asteacher.bean.BindingAuditInfo;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.utils.UserManger;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 学生绑定审核
 * Created by Administrator on 2017/7/18.
 */

public class BindingAuditAty extends BaseAty {

    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.listview)
    ListView listview;
    @Bind(R.id.tv_empty)
    TextView tvEmpty;

    List<BindingAuditInfo> list;
    BindingAuditAdapter adapter;

    BindingAuditInfo item;//临时点击的item

    @Override
    public int getLayoutId() {
        return R.layout.binding_audit_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar,"学生绑定审核");

        list = new ArrayList<>();
        adapter = new BindingAuditAdapter(this,list,R.layout.binding_audit_item);
        listview.setAdapter(adapter);
        listview.setEmptyView(tvEmpty);
    }

    @Override
    public void requestData() {
        showLoadingContent();
        new Teacher().apply(UserManger.getId(),this,0);
    }

    @Override
    public void intoActivity(Object object, int what) {
        item = (BindingAuditInfo) object;
        if (what == 0){
            showLoadingDialog("");
            new Teacher().shenhe(item.getId(),"3",this,1);
        }else if(what == 1){
            showLoadingDialog("");
            new Teacher().shenhe(item.getId(),"2",this,2);
        }
        super.intoActivity(object, what);
    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                list.clear();
                list.addAll(AppJsonUtil.getArrayList(result,BindingAuditInfo.class));
                adapter.notifyDataSetChanged();
                break;
            case 1:
                showToast(AppJsonUtil.getResultInfo(result).getMessage());
                new Teacher().apply(UserManger.getId(),this,0);
                break;
            case 2:
                showToast(AppJsonUtil.getResultInfo(result).getMessage());
                new Teacher().apply(UserManger.getId(),this,0);
                break;
        }
        super.onSuccess(result, call, response, what);
    }
}
